﻿<?php 
class Former_model extends CI_Model{
	function __construct(){
		parent::__construct();
		$this->load->database();
		$this->load->helper('url');
	}
	function get_message_desc($table){//按id倒叙排列
		$sql="select * from $table order by id desc";
		$res=$this->db->query($sql);
		return $res->result();
	}
	function get_message($table){//按id排列
		$sql="select * from $table";
		$res=$this->db->query($sql);
		return $res->result();
	}
	//插入报名信息
	function insert_enroll(){
		$name=$this->input->post('name');
		$grade=$this->input->post('grade');
		$major=$this->input->post('major');
		$qq=$this->input->post('qq');
		$phone=$this->input->post('phone');
		$email=$this->input->post('email');
		$content=$this->input->post('content');
		$data=array(
					'name'=>$name,
					'grade'=>$grade,
					'major'=>$major,
					'qq'=>$qq,
					'phone'=>$phone,
					'email'=>$email,
					'content'=>$content
                    );
		$query=$this->db->insert("enroll",$data);
		if($query){
			$flag=true;
			require_once "./class/email.class.php";
			$smtpserver = "smtp.qq.com";	//SMTP 服务器
			$smtpserverport = 25;			//SMTP·端口
			$smtpusermail = "905407339@qq.com";				//SMTP·发件箱
			$smtpemailto = "$email";				//收件箱
			$smtpuser = "905407339@qq.com";					//SMTP·用户名
			$smtppass = "yang905407339";					//SMTP 密码
			$mailtitle = "欢迎加入107网站工作室";				//主题
			$mailcontent = "欢迎加入107网站工作室";				//内容
			$mailtype = "HTML";				//格式
			$smtp = new smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass);
			$smtp->debug = true;//是否显示发送调试信息
			$state = $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);
		}else{
			$flag=false;
		}
		
		return $flag;	
	}
	
}